package com.itheima.demo2method;

public class ThreadApiDemo1 {
    public static void main(String[] args){
//        目标：搞清楚线程的常用方法
        Thread t1 = new MyThread("线程1");
//        t1.setName("线程一");
        t1.start();
        System.out.println(t1.getName());

        Thread t2 = new MyThread("线程2");
//        t2.setName("线程二");
        t2.start();
        System.out.println(t2.getName());
//        哪个线程调用这个代码，这个代码就拿到哪个线程对象
        Thread m=Thread.currentThread();
        m.setName("主线程");
        System.out.println(m.getName());//主线程的名字main
    }
}
class MyThread extends Thread{
    public MyThread(String name){
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"-->"+i);
        }
    }
}